<?php
$table = $this->uri->segment(3,0);
$url_ajax = base_url().'admin/ajax_field/order';
$url_ajax_sotrang = base_url().'admin/ajax_field/num';
$url_ajax_pub = base_url().'admin/ajax_field/pub/'.$table;
$url_ajax_where = base_url().'admin/ajax_field/where/'.$table;
?>
<!-- Noi dung bai viet-->
<script>
$(document).ready(function(){
  
    //*******************order ajax****************************************
    $(".box_noidung .ajax").click(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).attr('href');
        var url1 = '<?php echo $url_ajax;?>';
        $.ajax({
          		status: "POST",
          		url: url1,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    
    //*********************chon so trang**********************************
    $(".chon_trang #sotrang").change(function () {       
        //$('.loading').html('fdsfds');
        var data= $(this).val();
        var url2 = '<?php echo $url_ajax_sotrang;?>';
        $.ajax({
          		status: "POST",
          		url: url2,
          		data: {data: data},
                success: callback,
                error: err
        		});
         
        return false;
    });
    function succes (data, status){
       // var id = '#p'+data;
        //alert(id);
        $(data).toggleClass('unpublish');
    }
    function callback(data, status){
        location.reload();
        //$("div .box_ajax").html(data);
      }
    
	function err(xhr, reason, ex){
	   alert('loi');
        $("div .box_ajax").html('loi');
      }
//*****************end order ajax******************/
});

</script>
<div class="baiviet_admin">
<form method="POST" action="<?php echo base_url().'admin/xuly/order/them';?>">
<div class="box_heading">
    <div class="icon">
    <img src="<?php echo base_url().'template/admin/images/icon_sitemap.png';?>"/> 
    Tin tức: <?php 
    if($this->session->userdata('thongbao')){
        echo '<img src='.base_url().'template/admin/images/ok.png class="ok"><font color=red><b>'.$this->session->userdata('thongbao').'</b></font>';
        $this->session->unset_userdata('thongbao');
        }?>
    </div>
    <div class="right">
    </div>
</div>

<div class="box_noidung">
<table class="form">
<tr>
    <th style="width:5%"><a class="ajax" href="id">id</a><?php if($this->session->userdata('order')=='id'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th ><a title="" class="ajax" href="username">Tên đăng nhập</a><?php if($this->session->userdata('order')=='username'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th ><a title="" class="ajax" href="email">Email</a><?php if($this->session->userdata('order')=='email'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th ><a class="ajax" href="phone">Điện thoại</a><?php if($this->session->userdata('order')=='phone'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th ><a title="" class="ajax" href="name">Ngày</a><?php if($this->session->userdata('order')=='created'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th ><a class="ajax" href="status">Xem</a><?php if($this->session->userdata('order')=='status'){echo $this->session->userdata('sapxep')=='DESC'? '<div class="desc"></div>':'<div class="asc"></div>'; }?></th>
    <th style="width:5%">Xóa</th>
    
</tr>
<?php 

$this->db->select('*');
$this->db->from('users');
$this->db->join('order', 'order.id_user = users.id');
$query = $this->db->get();
$data= $query->result();
if(!empty($data)){
    foreach ($data as $data){
        echo '
        <tr>
        <td>'.$data->id.'</td>
       <td>'.$data->username.'</td>
        <td>'.$data->email.'</td>
        <td>'.$data->phone.'</td>
         <td>'.$data->created.'</td>
        ';           
                                            
        echo '
        <td><a href="'.base_url().'admin/xuly/order/edit/'.$data->id.'" class="edit"><img src="';
        if($data->status==0){
            echo base_url().'skin/admin/images/new.gif';
        }else echo base_url().'skin/admin/images/old.gif';
        
        echo '" title="Sửa"></a></td>
        <td><a onclick="return confirm(\'Bạn có muốn xóa không?\');" href="'.base_url().'admin/xuly/order/xoa/'.$data->id.'"><img src="'.base_url().'skin/admin/images/xoa.png" title="xóa"></a></td>
        
        </tr>                           
        ';
    }                          
                                
}?>

</table>
<!--chon so traang-->
<div class="chon_trang">
Số bài hiển thị:
<select name="sotrang" id="sotrang" class="inputbox" size="1">
<?php 
for( $i=10;$i<=100;$i){ 
    echo '<option value="'.$i.'" ';
    if($this->session->userdata('rows_per_page_baiviet')==$i){echo 'selected="selected"';}
    echo '>'.$i.'</option>';
    $i=$i+10;
}
for( $i=200;$i<=500;$i){ 
    echo '<option value="'.$i.'" ';
    if($this->session->userdata('rows_per_page_baiviet')==$i){echo 'selected="selected"';}
    echo '>'.$i.'</option>';
    $i=$i+100;
}
 
 ?>
</select>
</div>
<!--end chon so trang-->
<!-- chon danh muc-->
<div class="chon_danhmuc">
Lọc dữ liệu:
<select name="cat" class="locdulieu">
        <option <?php echo $dt=$this->session->userdata('goc'); if($dt==1){echo 'selected="selected"';}?> value="t0" class="locked">Chọn tất cả</option>
                            <option <?php $dt=$this->session->userdata('goc'); if($dt==2){echo 'selected="selected"';}?> value="goc" class="locked">Danh mục gốc</option>
                            <?php 
                            $value_where = $this->session->userdata('value_where');
                            if(!empty($cat)){
                                foreach($cat as $cat){
                                    echo '<option value="'.$cat->id.'" class="locked"';
                                    echo $value_where==$cat->id? 'selected="selected"':''; 
                                    echo '>'.$cat->title.'</option>';
                                }
                            }
                            ?>
</select> 
</div>
<!-- end chon danh muc-->
<!--phan trang-->

						<div class="pagination pagination-left">
							<div class="results">
								<span><?php if($result_mensenger){echo $result_mensenger;}?></span>
							</div>                            
							<ul class="pager">
							<?php	echo $this->pagination->create_links();?>
							</ul>   
						</div>
					

<!-- end phan trang-->
</div>
</form>
</div>

<!--end noi dung bai viet-->
